#!/bin/bash
  # Copying files

ROOT_UID=0
DEST_DIR=

# Destination directory
if [ "$UID" -eq "$ROOT_UID" ]; then
  DEST_DIR="/usr/share/themes"
else
  DEST_DIR="$HOME/.themes"
fi

repodir=$(cd $(dirname $0) && pwd)
srcdir=${repodir}/src

 rm -rf $DEST_DIR/Vimix*

 echo

for variant in '' '-Dark' '-Light' ; do
  for size in '' '-Laptop' ; do
	for color in '' '-Ruby' '-Doder' '-Beryl'; do
		echo -e "   Installing Vimix${variant}${size}${color} ..."

		themedir=$DEST_DIR/Vimix${variant}${size}${color}
		install -d ${themedir}

		# Install index.theme
		echo "[Desktop Entry]" >> ${themedir}/index.theme
		echo "Type=X-GNOME-Metatheme" >> ${themedir}/index.theme
		echo "Name=Vimix${variant}${size}${color}" >> ${themedir}/index.theme
		echo "Comment=An Flat Gtk+ theme based on Material Design" >> ${themedir}/index.theme
		echo "Encoding=UTF-8" >> ${themedir}/index.theme
		echo "" >> ${themedir}/index.theme
		echo "[X-GNOME-Metatheme]" >> ${themedir}/index.theme
		echo "GtkTheme=Vimix${variant}${size}${color}" >> ${themedir}/index.theme
		echo "MetacityTheme=Vimix${variant}${size}${color}" >> ${themedir}/index.theme
		echo "IconTheme=Adwaita" >> ${themedir}/index.theme
		echo "CursorTheme=Adwaita" >> ${themedir}/index.theme
		echo "ButtonLayout=menu:minimize,maximize,close" >> ${themedir}/index.theme

		# Install GNOME Shell Theme
		install -d ${themedir}/gnome-shell
		cd ${srcdir}/gnome-shell
		cp -ur \
			extensions \
			pad-osd.css \
			message-indicator-symbolic.svg \
			${themedir}/gnome-shell

		cp -ur \
			gnome-shell${variant}${size}${color}.css \
			${themedir}/gnome-shell/gnome-shell.css

		install -d ${themedir}/gnome-shell/assets
		cd ${srcdir}/gnome-shell/assets

		cp -ur \
			dash \
			dash-placeholder.svg \
			noise-texture.svg \
			process-working.svg \
			window-close.svg \
			window-close-active.svg \
			key-enter.svg \
			key-shift-latched-uppercase.svg \
			key-shift-uppercase.svg \
			${themedir}/gnome-shell/assets

		cp -ur \
			no-events${variant}.svg \
			${themedir}/gnome-shell/assets/no-events.svg

		cp -ur \
			no-notifications${variant}.svg \
			${themedir}/gnome-shell/assets/no-notifications.svg 

		cp -ur \
			calendar-arrow-left${variant}.svg \
			${themedir}/gnome-shell/assets/calendar-arrow-left.svg

		cp -ur \
			calendar-arrow-right${variant}.svg \
			${themedir}/gnome-shell/assets/calendar-arrow-right.svg

		cp -ur \
			checkbox${color}.svg \
			${themedir}/gnome-shell/assets/checkbox.svg

		cp -ur \
			checkbox-off${variant}.svg \
			${themedir}/gnome-shell/assets/checkbox-off.svg

		cp -ur \
			close${variant}.svg \
			${themedir}/gnome-shell/assets/close.svg

		cp -ur \
			more-results${color}.svg \
			${themedir}/gnome-shell/assets/more-results.svg

		cp -ur \
			toggle-off${variant}.svg \
			${themedir}/gnome-shell/assets/toggle-off.svg

		cp -ur \
			toggle-on${color}.svg \
			${themedir}/gnome-shell/assets/toggle-on.svg

		cp -ur \
			key-hide${variant}.svg \
			${themedir}/gnome-shell/assets/key-hide.svg

		cp -ur \
			key-layout${variant}.svg \
			${themedir}/gnome-shell/assets/key-layout.svg

		cp -ur \
			key-shift${variant}.svg \
			${themedir}/gnome-shell/assets/key-shift.svg

		cd ${themedir}/gnome-shell
		ln -s assets/no-events.svg no-events.svg
		ln -s assets/process-working.svg process-working.svg
		ln -s assets/no-notifications.svg no-notifications.svg

#		cd ${srcdir}/gnome-shell
#		glib-compile-resources \
#			--sourcedir=${themedir}/gnome-shell \
#			--target=${themedir}/gnome-shell/gnome-shell-theme.gresource \
#			gnome-shell-theme.gresource.xml

		# Install GTK+ 2 Theme
		install -d ${themedir}/gtk-2.0
		cd ${srcdir}/gtk-2.0

		cp -ur \
			gtkrc${variant}${color} \
			${themedir}/gtk-2.0/gtkrc

		cp -ur \
			common/apps.rc \
			common/hacks.rc \
			common/main.rc \
			common/panel.rc \
			common/xfce-notify.rc \
			${themedir}/gtk-2.0

		install -d ${themedir}/gtk-2.0/assets
		cd ${srcdir}/gtk-2.0/assets/Vimix${color}
		cp -ur \
			assets${variant}/*.png \
			${themedir}/gtk-2.0/assets/

		# Install GTK+ 3 Theme
		install -d ${themedir}/gtk-3.0
		cd ${srcdir}/gtk-3.0
		cp -ur \
			thumbnail${variant}${color}.png \
			${themedir}/gtk-3.0/thumbnail.png
		cp -ur \
			windows-assets/windows-assets \
			${themedir}/gtk-3.0/
		cp -ur \
			assets${color}/assets \
			${themedir}/gtk-3.0/
		cp -ur \
			scalable \
			${themedir}/gtk-3.0/assets/
		cp -ur \
			gtk${variant}${size}${color}.css \
			${themedir}/gtk-3.0/gtk.css
		cp -ur \
			gtk-Dark${size}${color}.css \
			${themedir}/gtk-3.0/gtk-dark.css

		# Install Metacity Theme
		install -d ${themedir}/metacity-1
		cd ${srcdir}/metacity-1
		cp -ur \
			assets/*.png \
			${themedir}/metacity-1

		cp -ur \
			metacity-theme-1${variant}${color}.xml \
			${themedir}/metacity-1/metacity-theme-1.xml

		cd ${themedir}/metacity-1
		ln -s metacity-theme-1.xml metacity-theme-2.xml
		ln -s metacity-theme-1.xml metacity-theme-3.xml

		# Install Unity Theme
		cd ${srcdir}
		cp -ur \
			unity \
			${themedir}

		# Install xfwm4 Theme
		install -d ${themedir}/xfwm4
		cd ${srcdir}/xfwm4

		cp -ur \
			assets${variant}${color}/*.png \
			${themedir}/xfwm4

		cp -ur \
			themerc${variant} \
			${themedir}/xfwm4/themerc
	done
  done
done

